package com.changyue.activity.history;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;

import com.changyue.activity.basic.BasicActivity;
import com.changyue.activity.history.entity.HistoryDataEntity;
import com.changyue.temp.databinding.ActivityResultBinding;
import com.changyue.util.CustomToast;
import com.changyue.util.EmptyUtil;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class ResultActivity extends BasicActivity {
    public final static String TAG = "ResultActivity";

    public final static String INTENT_KEY = "type";

    private ActivityResultBinding binding;

    private HistoryDataEntity historyDataEntity = null;

    public static void start(Context context, HistoryDataEntity historyDataEntity) {
        Intent intent = new Intent(context, ResultActivity.class);
        intent.putExtra(INTENT_KEY, historyDataEntity);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);

        binding = ActivityResultBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        historyDataEntity = getIntent().getParcelableExtra(INTENT_KEY);

        if (EmptyUtil.isEmpty(historyDataEntity)) {
            return;
        }

        final Calendar c = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分");
        String date = sdf.format(c.getTime());
        historyDataEntity.save_date = date;

        binding.idDetectionResult.setLineSpacing(10, 1.5f);
        binding.idDetectionResult.setText(historyDataEntity.getResultInfo(this));
    }

    public void onBtnContinue(View view) {
        Log.d(TAG, " -> onBtnContinue");

        if (EmptyUtil.isEmpty(historyDataEntity)) {
            return;
        }
        DataManager.saveHistory(historyDataEntity);

        CustomToast.middleBottom(this, "保存成功");
        finish();
    }

    public void onBtnCancel(View view) {
        finish();
    }
}
